package com.woniuxy.auth.controller;/*
@author houguai
@create 2021-03-05 10:40
*/

import com.woniuxy.ticketcommon.ResponceResult;
import org.apache.http.client.utils.URIBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;

@RestController
public class AuthController {

    @Value("${server.port}")
    private int port;

    @RequestMapping("auth")
    public ResponceResult<Void> auth(String jwt,String url) throws URISyntaxException {
        //发送HTTP请求到本项目，会经过Shiro过滤器
        RestTemplate restTemplate=new RestTemplate();

        URI uri=new URIBuilder().setScheme("http").setHost("localhost").setPort(port).setPath(url).build();
        HttpHeaders headers=new HttpHeaders();
        headers.add("jwt",jwt);

        headers.set("Accept", "application/json");

        ResponceResult<Void> responceResult=restTemplate.postForObject(uri,new HttpEntity<String>(headers),ResponceResult.class);

        return responceResult;
    }

}
